package edu.ihs.lhpy.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import edu.ihs.lhpy.base.BaseAction;
import edu.ihs.lhpy.domain.Institute;
import edu.ihs.lhpy.domain.PageBean;

@Controller
@Scope("prototype")
public class InstituteAction extends BaseAction<Institute> {

	/* 列表 */
	public String list() throws Exception {
//		List<Institute> instituteList = instituteService.findAll();
		PageBean pageBean = instituteService.getPageBean(pageNum);
		ActionContext.getContext().getValueStack().push(pageBean);
		return "list";
	}

	/* 添加 */
	public String add() throws Exception {
		// 保存到数据库中
		instituteService.save(model);
		return "toList";
	}

	/* 添加页面 */
	public String addUI() throws Exception {
		return "saveUI";
	}

	/* 修改 */
	public String edit() throws Exception {
		//取出原状态对象
		Institute institute = instituteService.getById(model.getId());
		//修改参数
		institute.setContent(model.getContent());
		institute.setHome_page(model.getHome_page());
		institute.setHuibiao(model.getHuibiao());
		institute.setName(model.getName());
		
		instituteService.update(institute);
		return "toList";
	}

	/* 修改页面 */
	public String editUI() throws Exception {
		// 准备回显的数据
		Institute institute = instituteService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(institute);
		
		return "saveUI";
	}

	/* 删除 */
	public String delete() throws Exception {
		instituteService.delete(model.getId());
		return "toList";
	}

	
	
}
